local skel = fk.CreateSkill {
  name = "emo__touxin",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__touxin"] = "偷心",
  [":emo__touxin"] = "每当你进入濒死状态时，你须令一名其他角色交给你一张牌，然后你展示此牌，若为<font color='#CC3131'>♥</font>牌，跳过此次求桃和死亡结算。",

  ["#emo__touxin-choose"] = "偷心：令一名其他角色交给你一张牌！",
  ["#emo__touxin-give"] = "偷心：你须交给 %src 一张牌，若为<font color='#CC3131'>♥</font>牌，其不死",
}

skel:addEffect(fk.EnterDying, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player == target and player:hasSkill(skel.name) and player.dying
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
    if #targets == 0 then return false end
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name, cancelable = false,
      prompt = "#emo__touxin-choose",
    })
    local to = tos[1]
    local cards = room:askToCards(to, {
      min_num = 1, max_num = 1, include_equip = true, cancelable = false, skill_name = skel.name,
      prompt = "#emo__touxin-give:"..player.id,
    })
    room:obtainCard(player, cards[1], true, fk.ReasonGive, to, skel.name)
    player:showCards(cards)
    if Fk:getCardById(cards[1]).suit == Card.Heart then
      data.ignoreDeath = true
      data.extra_data = data.extra_data or {}
      data.extra_data.emo__touxin_skip = true
    end
  end,
})

-- 防止求桃
skel:addEffect(fk.AskForPeaches, {
  mute = true,
  is_delay_effect = true,
  priority = 10,
  can_trigger = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.emo__touxin_skip
  end,
  on_use = function(self, event, target, player, data)
    return true
  end,
})

return skel
